#include "../include/game.h"
#include "../include/level.h"
#include "../include/map.h"

struct s_level{
	t_map* maps; // array of the level's maps
	ushort nb_maps; // nb maps of the level
	ushort cur_map; // the current map
};

t_level level_get_level(int num) {
	t_level level = malloc(sizeof(struct s_level));
	switch(num) {
	case 1 :
		level->nb_maps = 3;
		level->cur_map = 0;
		level->maps = malloc(sizeof (*level->maps));
		level->maps[0] = /*map_get_default()*/map_get_current(0,0);
		level->maps[1]=map_get_current(0,1);
		level->maps[2]=map_get_current(0,2);
		return level;
		break;
	case 2:
		level->nb_maps = 3;
		level->cur_map = 0;
		level->maps = malloc(sizeof (*level->maps));
		level->maps[0] =map_get_current(1,0);
		level->maps[1]=map_get_current(1,1);
		level->maps[2]=map_get_current(1,2);
		return level;
		break;
	case 3:
		level->nb_maps = 3;
		level->cur_map = 0;
		level->maps = malloc(sizeof (*level->maps));
		level->maps[0] =map_get_current(2,0);
		level->maps[1]=map_get_current(2,1);
		level->maps[2]=map_get_current(2,2);
		return level;
		break;
	case 4:
			level->nb_maps = 1;
			level->cur_map = 0;
			level->maps = malloc(sizeof (*level->maps));
			level->maps[0] =map_get_current(3,0);
			return level;
			break;


	}
	return NULL;
}

t_map level_get_curr_map(t_level level) {
	return level->maps[level->cur_map];
}

//attention fonction apres
void change_current_map(t_level level,t_player player){
	level->cur_map=player_get_var_map(player);
}

t_map level_get_map(t_level level, int num) {
	assert(num <= level->nb_maps);
	return level->maps[num];
}

void level_free(t_level level) {
	for(int i = 0; i < level->nb_maps; i++) {
		map_free(level->maps[i]);
	}
	free(level->maps);
}

void level_display(t_level level, SDL_Surface* screen) {
	map_display(level->maps[level->cur_map], screen);
}

